const express = require("express");
const bodyParser = require("body-parser");

const pool = require('./db');
const cors = require('cors');


const app = express();
const port = 3000;


// 使用中间件解析json
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

const userRoutes = require("./routes/user")(pool);
const bookRoutes = require("./routes/books")(pool);


app.use("/user", userRoutes);
app.use("/books", bookRoutes);

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`);
})